package com.ls.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.tedu.crm.entity.Customer;
import cn.tedu.crm.service.ICustomerService;
import cn.tedu.crm.util.JsonResult;

@Controller
@RequestMapping("/customer")
public class CustomerController {
	@Resource(name = "customerService")
	ICustomerService service;
	
	/**
	 * 查询全部客户
	 * @param pageId  默认第一页
	 * @param num	一页几条记录
	 * @return
	 */
	@RequestMapping("/listAllcs.do")
	@ResponseBody
	public JsonResult<List<Customer>> findCustomerFenye(@RequestParam(value = "pageId", defaultValue = "1") int pageId,
			@RequestParam(value = "num", defaultValue = "4") int num) {
		JsonResult<List<Customer>> result = service.findCustomerFenye(pageId, num);
		return result;
	}
	
	@RequestMapping("/deleteid.do")
	@ResponseBody
	public JsonResult<Object> deleteDept(String[] customer_id) {
		JsonResult<Object> result = service.deleteByIdCs(customer_id);
		return result;

	}
	
	@RequestMapping("/selecteName.do")
	@ResponseBody
	public JsonResult<List<Customer>> selectName(String name,@RequestParam(value = "pageId", defaultValue = "1") int pageId,
			@RequestParam(value = "num", defaultValue = "4") int num) {
		JsonResult<List<Customer>> result = service.findName(name, pageId, num);
		return result;

	}
	
	//---------option start------------
	@RequestMapping("/option.do")
	@ResponseBody
	public JsonResult<List<Customer>> findOption() {
		JsonResult<List<Customer>> result = service.findCustomer();
		return result;
	}
	@RequestMapping("/insert.do")
	@ResponseBody
	public JsonResult<Object> insertCustomer(Customer customer) {
		JsonResult<Object> result = service.insertCustomer(customer);
		return result;
		
	}
	@RequestMapping("/show.do")
	@ResponseBody
	public JsonResult<Customer> showCustomer(int customer_id) {
		JsonResult<Customer> result = service.showCu(customer_id);
		return result;
		
	}
	
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonResult<Object> updateCustomer(Customer customer) {
		JsonResult<Object> result = service.updateCustomer(customer);
		return result;
		
	}
	
}
